using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
    /// <summary>
    /// Controller class for CSK_Store_AttributeTemplate
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class AttributeTemplateController 
    {
        // Preload our schema..
        AttributeTemplate thisSchemaLoad = new AttributeTemplate();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public AttributeTemplateCollection FetchAll()
        {
            AttributeTemplateCollection coll = new AttributeTemplateCollection();
            Query qry = new Query(AttributeTemplate.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public AttributeTemplateCollection FetchByID(object TemplateID)
        {
            AttributeTemplateCollection coll = new AttributeTemplateCollection().Where("templateID", TemplateID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public AttributeTemplateCollection FetchByQuery(Query qry)
        {
            AttributeTemplateCollection coll = new AttributeTemplateCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object TemplateID)
        {
            return (AttributeTemplate.Delete(TemplateID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object TemplateID)
        {
            return (AttributeTemplate.Destroy(TemplateID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string AttributeName,string  Description,int AttributeTypeID,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy)
	    {
		    AttributeTemplate item = new AttributeTemplate();
		    
            item.AttributeName = AttributeName;
            
            item.Description = Description;
            
            item.AttributeTypeID = AttributeTypeID;
            
            item.CreatedOn = CreatedOn;
            
            item.CreatedBy = CreatedBy;
            
            item.ModifiedOn = ModifiedOn;
            
            item.ModifiedBy = ModifiedBy;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int TemplateID,string AttributeName,string Description,int AttributeTypeID,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy)
	    {
		    AttributeTemplate item = new AttributeTemplate();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
				item.TemplateID = TemplateID;
				
			item.AttributeName = AttributeName;
				
				item.Description = Description;
				
				item.AttributeTypeID = AttributeTypeID;
				
				item.CreatedOn = CreatedOn;
				
				item.CreatedBy = CreatedBy;
				
				item.ModifiedOn = ModifiedOn;
				
				item.ModifiedBy = ModifiedBy;

		    item.Save(UserName);
	    }

    }

}

